<template>
  <ToolbarButton
    icon="i-ri-align-justify"
    title="分散对齐"
    shortcut="Ctrl+Shift+D"
    :active="isActive"
    @click="handleClick"
  />
</template>

<script setup lang="ts">
import { computed, inject, type Ref } from "vue";
import type { Editor } from "@tiptap/vue-3";
import ToolbarButton from "../../../button/index.vue";

defineOptions({
  name: "AlignDistributed",
});

// 注入编辑器实例
const editor = inject<Ref<Editor>>("editor");

const isActive = computed(() => {
  return editor?.value?.isActive({ textAlign: "distributed" });
});

const handleClick = () => {
  editor?.value?.chain().focus().setTextAlign("distributed").run();
};
</script>
